/**
 * @ClassName ProfitAnalysisController
 * @Description TODO
 * @Author 沉默小吴
 * @Date 2024/12/17 14:50
 */
package com.tledu.operate.count.controller;

import com.tledu.operate.count.entity.vo.ProfitAnalysisJSON;
import com.tledu.operate.count.service.IProfitAnalysisService;
import com.tledu.operate.count.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "http://localhost")
public class ProfitAnalysisController {

    @Autowired
    private IProfitAnalysisService profitAnalysisServiceImpl;

    @GetMapping("/profit-analysis")
    public ProfitAnalysisJSON getProfitAnalysis(
            @RequestParam Long departmentId,
            @RequestParam String startDate,
            @RequestParam String endDate,
            @RequestParam String granularity) {
        return profitAnalysisServiceImpl.getProfitAnalysis(departmentId, DateUtils.initializeDateTimes(startDate, endDate)[0], DateUtils.initializeDateTimes(startDate, endDate)[1], granularity);
    }
}